﻿using System;
using System.Collections.Generic;
using System.Linq;
using Director.DomainModels;

namespace Director
{
	class OrdersRegistrator
	{
		private static OrdersRegistrator _instance;
		private readonly List<Order> _orders = new List<Order>();
		private readonly List<Order> _realOrders = new List<Order>();

		public static OrdersRegistrator Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new OrdersRegistrator();
				}
				return _instance;
			}
		}

		public void RegisterBuy(Security security, int quantity, decimal price, DateTime dt)
		{
			_orders.Add(new Order { OrderNo = _orders.Count + 1, IsBuy = true, Quantity = quantity, SecCode = security.Code, Time = dt });
		}

		public void RegisterSell(Security security, int quantity, decimal price, DateTime dt)
		{
			_orders.Add(new Order { OrderNo = _orders.Count + 1, IsBuy = false, Quantity = quantity, SecCode = security.Code, Time = dt });
		}
		
		public void RegisterOrder(Order order)
		{
			_realOrders.Add(order);
		}

		public Order[] GetOrders(Security security, bool isReal)
		{
			return (isReal?_realOrders:_orders).Where(e => e.SecCode == security.Code).OrderBy(e => e.Time).ToArray();
		}
	}
}
